home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / editors / emacs / emacs-19.000 / emacs-19 / usr / local / info / viper-1 < prev    next >
Encoding:
GNU Info File  |  1995-09-11  |  45.4 KB  |  1,014 lines

  1. This is Info file ../info/viper, produced by Makeinfo-1.55 from the
  2. input file viper.texi.
  3.  
  4.    %
  5.  
  6. Distribution
  7. ************
  8.  
  9. Copyright (C) 1991 Aamod Sane
  10. Copyright (C) 1994 Michael Kifer
  11.  
  12.    Permission is granted to make and distribute verbatim copies of this
  13. manual provided the copyright notice and this permission notice are
  14. preserved on all copies.
  15.  
  16.    Permission is granted to copy and distribute modified versions of
  17. this manual under the conditions for verbatim copying, provided that
  18. the entire resulting derived work is distributed under the terms of a
  19. permission notice identical to this one.
  20.  
  21.    Permission is granted to copy and distribute translations of this
  22. manual into another language, under the same conditions as for modified
  23. versions.
  24.  
  25. 
  26. File: viper,  Node: Top,  Next: Overview,  Up: (DIR)
  27.  
  28. Viper
  29. *****
  30.  
  31.    We believe that one or more of the following statements are adequate
  32. descriptions:
  33.  
  34.      Viper Is a Package for Emacs Rebels;
  35.      it is a VI Plan for Emacs Rescue
  36.      and/or a venomous VI PERil.
  37.  
  38.    Technically speaking, Viper is a Vi emulation package for GNU Emacs
  39. 19 and XEmacs 19. Because of its reliance on minor mode keymaps, Viper
  40. will not work under Emacs 18. Viper implements most Vi and Ex commands.
  41. It gives you the best of both worlds: Vi keystrokes for editing
  42. combined with the GNU Emacs environment. Viper also fixes some common
  43. complaints with Vi commands.  This manual describes Viper,
  44. concentrating on the differences from Vi and new features of Viper.
  45.  
  46.    Viper is a new name for a package formerly known as VIP-19.  VIP-19,
  47. in turn, was based on VIP 3.5 by Masahiko Sato and VIP version 4.4 by
  48. Aamod Sane, and it tries to be compatible with these packages.
  49.  
  50.    Viper is intended to be usable without reading this manual -- the
  51. defaults are set to make Viper as close to Vi as possible.  At startup,
  52. Viper will try to set the most appropriate default environment for you,
  53. based on your familiarity with Emacs. It will also tell you the basic
  54. GNU Emacs window management commands to help you start immediately.
  55.  
  56.    Although this manual explains how to customize Viper, some basic
  57. familiarity with Emacs Lisp would be a plus.
  58.  
  59.    It is recommended that you read the Overview node. The other nodes
  60. may be visited as needed.
  61.  
  62.    Comments and bug reports are welcome.  `kifer@cs.emacs.edu' is the
  63. current address for Viper bug reports.  Please use the Ex command
  64. `:submitReport' for this purpose.
  65.  
  66. * Menu:
  67.  
  68. * Overview::            Must read to get started
  69. * Improvements over Vi::    New features, Improvements
  70. * Customization::        How to customize Viper
  71. * Commands::            Vi and Ex Commands
  72.  
  73. * Key Index::            Index of Vi and Ex Commands
  74. * Function Index::              Index of Viper Functions
  75. * Variable Index::              Index of Viper Variables
  76. * Package Index::               Index of Packages Mentioned in this Document
  77. * Concept Index::        Vi, Ex and Emacs concepts
  78.  
  79. * Acknowledgments::
  80.  
  81. 
  82. File: viper,  Node: Overview,  Next: Improvements over Vi,  Prev: Top,  Up: Top
  83.  
  84. Overview of Viper
  85. *****************
  86.  
  87.    Viper is a Vi emulation on top of Emacs. At the same time, Viper
  88. provides a virtually unrestricted access to Emacs facilities. Perfect
  89. compatibility with Vi is possible but not desirable. This chapter tells
  90. you about the Emacs ideas that you should know about, how to use Viper
  91. within Emacs and some incompatibilities.
  92.  
  93.    Viper was formerly known as VIP-19, which was a descendant of VIP
  94. 3.5 by Masahiko Sato and VIP 4.4 by Aamod Sane.
  95.  
  96. * Menu:
  97.  
  98. * Emacs Preliminaries::        Basic concepts in Emacs.
  99. * Loading Viper::            Loading and Preliminary Configuration.
  100. * States in Viper::        Viper has four states orthogonal to
  101.                 modes in Emacs.
  102. * The Minibuffer::        Command line in Emacs.
  103. * Multiple Files in Viper::    True multiple file handling.
  104. * Unimplemented Features::    That are unlikely to be implemented.
  105.  
  106. 
  107. File: viper,  Node: Emacs Preliminaries,  Next: Loading Viper,  Prev: Overview,  Up: Overview
  108.  
  109. Emacs Preliminaries
  110. ===================
  111.  
  112.    Emacs can edit several files at once. A file in Emacs is placed in a
  113. "buffer" that usually has the same name as the file. Buffers are also
  114. used for other purposes, such as shell interfaces, directory editing,
  115. etc.  *Note Directory Editor: (emacs)Dired, for an example.
  116.  
  117.    A buffer has a distinguished position called the "point".  A "point"
  118. is always between 2 characters, and is "looking at" the right hand
  119. character. The cursor is positioned on the right hand character. Thus,
  120. when the "point" is looking at the end-of-line, the cursor is on the
  121. end-of-line character, i.e. beyond the last character on the line. This
  122. is the default Emacs behavior.
  123.  
  124.    The default settings of Viper try to mimic the behavior of Vi,
  125. preventing the cursor from going beyond the last character on the line.
  126. By using Emacs commands directly (such as those bound to arrow keys),
  127. it is possible to get the cursor beyond the end-of-line. However, this
  128. won't (or shouldn't) happen if you restrict yourself to standard Vi
  129. keys, unless you modify the default editing style. *Note
  130. Customization::.
  131.  
  132.    In addition to the "point", there is another distinguished buffer
  133. position called the "mark". *Note Mark: (emacs)Mark, for more info on
  134. the mark. The text between the "point" and the "mark" is called the
  135. "region" of the buffer. For the Viper user, this simply means that in
  136. addition to the Vi textmarkers a-z, there is another marker called
  137. "mark". This is similar to the unnamed Vi marker used by the jump
  138. commands (" and "), which move the cursor to the position of the last
  139. absolute jump.  Viper provides access to the region in most text
  140. manipulation commands as `r' and `R' suffix to commands that operate on
  141. text regions, e.g., `dr' to delete region, etc.  *Note Basics::, for
  142. more info.
  143.  
  144.    Emacs divides the screen into tiled "windows". You can see the
  145. contents of a buffer through the window associated with the buffer.  The
  146. cursor of the screen is positioned on the character after "point".
  147. Every window has a "mode line" that displays information about the
  148. buffer.  You can change the format of the mode line, but normally if
  149. you see `**' at the beginning of a mode line it means that the buffer
  150. is "modified".  If you write out the contents of a buffer to a file,
  151. then the buffer will become not modified.  Also if you see `%%' at the
  152. beginning of the mode line, it means that the file associated with the
  153. buffer is write protected. The mode line will also show the buffer name
  154. and current major and minor modes (see below).  A special buffer called
  155. "Minibuffer" is displayed as the last line in a Minibuffer window. The
  156. Minibuffer window is used for command input output. Viper uses
  157. Minibuffer window for `/' and `:' commands.
  158.  
  159.    An Emacs buffer can have a "major mode" that customizes Emacs for
  160. editing text of a particular sort by changing the functionality of the
  161. keys.  Keys are defined using a "keymap" that records the bindings
  162. between keystrokes and functions. The "global keymap" is common to all
  163. the buffers.  Additionally, each buffer has its "local keymap" that
  164. determines the "mode" of the buffer.  If a function is bound to some
  165. key in the local keymap then that function will be executed when you
  166. type the key.  If no function is bound to a key in the local map,
  167. however, the function bound to the key in the global map will be
  168. executed. *Note Major Modes: (emacs)Major Modes, for more information.
  169.  
  170.    A buffer can also have a "minor mode". Minor modes are options that
  171. you can use or not. A buffer in `text-mode' can have `auto-fill-mode'
  172. as minor mode, which can be turned off or on at any time. In Emacs 19, a
  173. minor mode may have it own keymap, which overrides the local keymap when
  174. the minor mode is turned on.  For more information, *note Minor Modes:
  175. (emacs)Minor Modes.
  176.  
  177.    Viper is implemented as a collection of minor modes. Different minor
  178. modes are involved when Viper emulates Vi command mode, Vi insert mode,
  179. etc.  You can also turn Viper on and off at any time while in Vi
  180. command mode.  *Note States in Viper::, for more information.
  181.  
  182.    Emacs uses Control and Meta modifiers. These are denoted as C and M,
  183. e.g. `^Z' as `C-z' and `Meta-x' as `M-x'.  The Meta key is usually
  184. located on each side of the Space bar; it is used in a manner similar
  185. to the Control key, e.g., `M-x' means typing `x' while holding the Meta
  186. key down.  For keyboards that do not have a Meta key, ESC is used as
  187. Meta.  Thus `M-x' is typed as `ESC x'. Viper uses ESC to switch from
  188. Insert state to Vi state. Therefore Viper defines `_' as its Meta key
  189. in Vi state. *Note Vi State::, for more info.
  190.  
  191.    Emacs is structured as a lisp interpreter around a C core. Emacs keys
  192. cause lisp functions to be called. It is possible to call these
  193. functions directly, by typing `M-x function-name'.
  194.  
  195. 
  196. File: viper,  Node: Loading Viper,  Next: States in Viper,  Prev: Emacs Preliminaries,  Up: Overview
  197.  
  198. Loading Viper
  199. =============
  200.  
  201.    First, make sure that all six Viper files `viper*.el' are somewhere
  202. on Emacs "load path". The load path is a list of directories where Emacs
  203. looks for its Lisp code; it is similar to Unix environment variable
  204. PATH.  The load path is determined by the Lisp variable `load-path'.
  205.  
  206.    Type `C-h v load-path RET' to check the current load path of your
  207. Emacs. (Here and later, `RET' stands for carriage return.) If the files
  208. `viper*.el' are not in any directory on the load path, you should
  209. create your own directory and put it on the load path; then put
  210. `viper*.el' in that directory.  To put a new directory, say
  211. `~/emacslib', on your load path, add the following line at the
  212. beginning of your `~/.emacs' file:
  213.      (setq load-path (cons "~/emacslib" load-path))
  214.    It is recommended that you compile `viper.el' by running
  215.      make all
  216.    in the directory where Viper was unpacked. The best way to ensure
  217. that Viper is installed properly is to run
  218.      make install
  219.    in the directory where Viper was unpacked. See README in the Viper
  220. distribution for the details on which modifications to the make file
  221. may be necessary.
  222.  
  223.    Once Viper is settled on the load path, the most common way to load
  224. it automatically is to include the line:
  225.  
  226.      (require 'viper)
  227.  
  228. in your `~/.emacs' file.  The `.emacs' file is placed in your home
  229. directory and it will be executed every time you invoke Emacs.  Viper
  230. also uses the file `~/.vip' for Viper-specific customization.  If you
  231. wish to be in Vi command state whenever this is appropriate, you can
  232. include the following line in your `.vip':
  233.      (setq vip-always t)
  234.  
  235. (*Note Vi State::, for the explanation of Vi mode.)
  236.  
  237.    Once invoked, Viper will arrange to bring up Emacs buffers in Vi
  238. state whenever this makes sense.  *Note Packages that Change Keymaps::,
  239. to find out when forcing Vi command state on a buffer may be
  240. counter-productive.
  241.  
  242.    Even if your `.emacs' and `.vip' files do not contain any of the
  243. above lines, you can still load Viper and enter Vi state by typing the
  244. following from within Emacs:
  245.  
  246.      M-x load-library RET viper RET
  247.      M-x viper-mode
  248.  
  249. Ask your local Emacs administrator if this fails to work.
  250.  
  251.    When Emacs first comes up, if you have not specified a file on the
  252. command line, it will show the `*scratch*' buffer, in the `Lisp
  253. Interaction' mode. After you invoke Viper, you can start editing files
  254. by using `:e', `:vi', or `v' commands.  (*Note File and Buffer
  255. Handling::, for more information on `v' and other new commands that, in
  256. many cases, are more convenient than `:e', `:vi', and similar old-style
  257. Vi commands.)
  258.  
  259. 
  260. File: viper,  Node: States in Viper,  Next: The Minibuffer,  Prev: Loading Viper,  Up: Overview
  261.  
  262. States in Viper
  263. ===============
  264.  
  265.    Viper has four states, Emacs, Vi, Insert, and Replace.
  266.  
  267. `Emacs state'
  268.      This is the mode plain vanilla Emacs is normally in. After you
  269.      have loaded Viper, `C-z' will normally take you to Vi command
  270.      state. Another `C-z' will take you back to Emacs state.  This
  271.      toggle key can be changed, *note Customization::. You can also
  272.      type `M-x viper-mode' to change to Vi state.
  273.  
  274.      For users who chose to set their user level to 1 at Viper setup
  275.      time, switching to Emacs state is deliberately made harder in
  276.      order to not confuse the novice user. In this case, `C-z' will
  277.      either iconify Emacs (if Emacs runs as an application under X
  278.      Windows) or it will stop Emacs (if Emacs runs on a dumb terminal
  279.      or in an Xterm window).
  280.  
  281. `Vi state'
  282.      This is the Vi command mode. Any of the Vi commands, such as `i,
  283.      o, a', ..., will take you to Insert state. All Vi commands may be
  284.      used in this mode. Most Ex commands can also be used.  For a full
  285.      list of Ex commands supported by Viper, type `:' and then `TAB'.
  286.      To get help on any issue, including the Ex commands, type `:help'.
  287.      This will invoke Viper Info (if it is installed). Then typing `i'
  288.      will prompt you for a topic to search in the index. Note, to
  289.      search for Ex commands in the index, you should start them with a
  290.      "`:'", e.g., `:WW'.
  291.  
  292. `Insert state'
  293.      Insert state is the Vi insertion mode. `ESC' will take you back to
  294.      Vi state. Insert state editing can be done, including
  295.      auto-indentation. By default, Viper disables Emacs keybindings in
  296.      Insert state.
  297.  
  298. `Replace state'
  299.      Commands like `cw' invoke the Replace state. When you cross the
  300.      boundary of a replacement region (usually designated via a `$'
  301.      sign), it will automatically change to Insert state. You do not
  302.      have to worry about it. The key bindings remain practically the
  303.      same as in Insert state. If you type ESC, Viper will switch to Vi
  304.      command mode, terminating the replacement state.
  305.  
  306.    The modes are indicated on the "mode line" as <E>, <I>, <V>, and <R>,
  307. so that the multiple modes do not confuse you. Most of your editing can
  308. be done in Vi and Insert states. Viper will try to make all new buffers
  309. be in Vi state, but sometimes they may come up in Emacs state.  `C-z'
  310. will take you to Vi state in such a case.  In some major modes, like
  311. Dired, Info, Gnus, etc., you should not switch to Vi state (and Viper
  312. will not attempt to do so) because these modes are not intended for
  313. text editing and many of the Vi keys have special meaning there. If you
  314. plan to read news, browse directories, read mail, etc., from Emacs
  315. (which you should start doing soon!), you should learn about the
  316. meaning of the various keys in those special modes (typing `C-h m' in a
  317. buffer provides help with key bindings for the major mode of that
  318. buffer).
  319.  
  320.    If you switch to Vi in Dired or similar modes--no harm is done. It
  321. is just that the special keybindings provided by those modes will be
  322. temporarily overshadowed by Viper's bindings. Switching back to Viper's
  323. Emacs state will revive the environment provided by the current major
  324. mode.
  325.  
  326.    States in Viper are orthogonal to Emacs major modes, such as C mode
  327. or Dired mode. You can turn Viper on and off for any Emacs state. When
  328. Viper is turned on, Vi state can be used to move around. In Insert
  329. state, the bindings for these modes can be accessed.  For beginners
  330. (users at Viper levels 1 and 2), these bindings are suppressed in
  331. Insert state, so that new users are not confused by the Emacs states.
  332. Note that unless you allow Emacs bindings in Insert state, you cannot
  333. do many interesting things, like language sensitive editing. For the
  334. novice user (at Viper level 1), all major mode bindings are turned off
  335. in Vi state as well. This includes the bindings for key sequences that
  336. start with `C-c', which practically means that all major mode bindings
  337. are supported.  *Note Customization::, to find out how to allow Emacs
  338. keys in Insert state.
  339.  
  340. * Menu:
  341.  
  342. * Emacs State::        This is the state you should learn more about when
  343.                         you get up to speed with Viper.
  344. * Vi State::        Vi commands are executed in this state.
  345. * Insert State::    You can enter text, and also can do sophisticated
  346.                         editing if you know enough Emacs commands.
  347. * Replace State::    Like Insert mode, but it is invoked via the
  348.                         replacement commands, such as cw, C, R, etc.
  349.  
  350. 
  351. File: viper,  Node: Emacs State,  Next: Vi State,  Prev: States in Viper,  Up: States in Viper
  352.  
  353. Emacs State
  354. -----------
  355.  
  356.    You will be in this mode only by accident (hopefully). This is the
  357. state Emacs is normally in (imagine!!). Now leave it as soon as
  358. possible by typing `C-z'. The you will be in Vi state (sigh of relief)
  359. :-).
  360.  
  361.    Emacs state is actually a Viperism to denote all the major and minor
  362. modes (*Note Emacs Preliminaries::)  other than Viper that Emacs can be
  363. in. Emacs can have several modes, such as C mode for editing C
  364. programs, LaTeX mode for editing LaTeX documents, Dired for directory
  365. editing, etc. These are major modes, each with a different set of
  366. key-bindings. Viper states are orthogonal to these Emacs major modes.
  367. The presence of these language sensitive and other modes is a major win
  368. over Vi.  *Note Improvements over Vi::, for more.
  369.  
  370.    The bindings for these modes can be made available in the Viper
  371. Insert state as well as in Emacs state.  Unless you specify your user
  372. level as 1 (a novice), all major mode key sequences that start with
  373. `C-x' and `C-c' are also available in Vi state.  This is important
  374. because major modes designed for editing files, such as cc-mode or
  375. latex-mode, use key sequences that begin with `C-x' and `C-c'.
  376.  
  377.    There is also a key that lets you temporarily escape to Vi command
  378. state from Emacs state: typing `M-C-z' (or `ESC C-z') will let you
  379. execute a single Vi command while staying in Viper's Emacs state.  At
  380. present, this works only for 1-character Vi commands (and for some
  381. complex commands).
  382.  
  383. 
  384. File: viper,  Node: Vi State,  Next: Insert State,  Prev: Emacs State,  Up: States in Viper
  385.  
  386. Vi State
  387. --------
  388.  
  389.    This is the Vi command mode. When Viper is in Vi state, you will see
  390. the sign <V> in the mode line. Most keys will work as in Vi. The notable
  391. exceptions are:
  392.  
  393. `C-x'
  394.      `C-x' is used to invoke Emacs commands, mainly those that do window
  395.      management. `C-x 2' will split a window, `C-x 0' will close a
  396.      window. `C-x 1' will close all other windows. `C-xb' is used to
  397.      switch buffers in a window, and `C-xo' to move through windows.
  398.      These are about the only necessary keystrokes.  For the rest, see
  399.      GNU Emacs Manual.
  400.  
  401. `C-c'
  402.      For user levels 2 and higher, this key serves as a prefix key for
  403.      the key sequences used by various major modes. For users at Viper
  404.      level 1, `C-c' simply beeps.
  405.  
  406. `C-g and C-]'
  407.      These are the Emacs `quit' keys.  There will be cases where you
  408.      will have to use `C-g' to quit. Similarly, `C-]' is used to exit
  409.      `Recursive Edits' in Emacs for which there is no comparable Vi
  410.      functionality and no key-binding. Recursive edits are indicated by
  411.      `[]' brackets framing the modes on the mode line.  *Note Recursive
  412.      Edit: (emacs)Recursive Edit.  At user level 1, `C-g' is bound to
  413.      `vip-info-on-file' function instead.
  414.  
  415. `Underscore'
  416.      Viper uses `ESC' as a switch between Insert and Vi states. Emacs
  417.      uses `ESC' for Meta. We need a Meta key to call the Meta key
  418.      functions such as `M-x function name'. The underscore key, `_',
  419.      was chosen, since it is the only reasonable, free Vi key left.
  420.      Thus, in Vi state, to get `M-x', you should type `_x' (if the
  421.      keyboard has no Meta key).  It is possible to use `ESC' as Meta,
  422.      but then you cannot press `ESC' multiple times in Vi state. *Note
  423.      Customization::, to find out how to rebind ESC to be Meta.
  424.  
  425. Other differences are mostly improvements. The ones you should know
  426. about are:
  427.  
  428. `Undo'
  429.      `u' will undo. Undo can be repeated by the `.' key. Undo itself
  430.      can be undone. Another `u' will change the direction. The presence
  431.      of repeatable undo means that `U', undoing lines, is not very
  432.      important. Therefore, `U' also calls `vip-undo'.
  433.  
  434. `Counts'
  435.      Most commands, `~', `[[', `p', `/', ..., etc., take counts.
  436.  
  437. `Regexps'
  438.      Viper uses Emacs Regular Expressions for searches. These are a
  439.      superset of Vi regular expressions, excepting the change-of-case
  440.      escapes `\u', `\L', ..., etc. *Note Regular Expressions:
  441.      (emacs)Regular Expressions, for details.  Files specified to `:e'
  442.      use `csh' regular expressions (globbing, wildcards, what have you).
  443.      However, the function `vip-toggle-search-style', bound to `C-c /',
  444.      lets the user switch from search with regular expressions to plain
  445.      vanilla search and vice versa. It also lets one switch from
  446.      case-sensitive search to case-insensitive and back.  *Note Viper
  447.      Specials::, for more details.
  448.  
  449. `Ex commands'
  450.      The current working directory of a buffer is automatically
  451.      inserted in the minibuffer if you type `:e' then space.  Absolute
  452.      filenames are required less often in Viper.  For path names, Emacs
  453.      uses a convention that is slightly different from that of Unix.
  454.      It is designed to minimize the need for deleting path names that
  455.      Emacs provides in its prompts. (This is usually convenient, but
  456.      occasionally the prompt may suggest a wrong path name for you.) If
  457.      you see a prompt `/usr/foo/' and you wish to edit the file
  458.      `~/.vip', you don't have to erase the prompt. Instead, simply
  459.      continue typing what you need. Emacs will interpret
  460.      `/usr/foo/~/.vip' correctly. Similarly, if the prompt is `~/foo/'
  461.      and you need to get to `/bar/file', keep typing. Emacs interprets
  462.      `~/foo//bar/' as `/bar/file', since when it sees `//', it
  463.      understands that `~/foo/' is to be discarded.
  464.  
  465.      The command `:cd' will change the default directory for the
  466.      current buffer. The command `:e' will interpret the filename
  467.      argument in `csh'. *Note Customization::, if you want to change
  468.      the default shell.  The command `:next' takes counts from `:args',
  469.      so that `:rew' is obsolete. Also, `:args' will show only the
  470.      invisible files (i.e., those that are not currently seen in Emacs
  471.      windows).
  472.  
  473.      When applicable, Ex commands support file completion and history.
  474.      This means that by typing a partial file name and then `TAB',
  475.      Emacs will try to complete the name or it will offer a menu of
  476.      possible completions.  This works similarly to Tcsh and extends
  477.      the behavior of Csh. While Emacs is waiting for a file name, you
  478.      can type `M-p' to get the previous file name you typed. Repeatedly
  479.      typing `M-p' and `M-n' will let you browse through the file
  480.      history.
  481.  
  482.      Like file names, partially typed Ex commands can be completed by
  483.      typing `TAB', and Viper keeps the history of Ex commands. After
  484.      typing `:', you can browse through the previously entered Ex
  485.      commands by typing `M-p' and `M-n'.  Viper tries to rationalize
  486.      when it puts Ex commands on the history list.  For instance, if
  487.      you typed `:w! foo', only `:w!'  will be placed on the history
  488.      list. This is because the last history element is the default that
  489.      can be invoked simply by typing `: RET'. If `:w! foo' were placed
  490.      on the list, it would be all to easy to override valuable data in
  491.      another file. Reconstructing the full command, `:w!  foo', from
  492.      the history is still not that hard, since Viper has a separate
  493.      history for file names. By typing `: M-p', you will get `:w!' in
  494.      the Minibuffer. Then, repeated `M-p' will get you through the file
  495.      history, inserting one file name after another.
  496.  
  497.      In contrast to `:w! foo', if the command were `:r foo', the entire
  498.      command will appear in the history list. This is because having
  499.      `:r' alone as a default is meaningless, since this command
  500.      requires a file argument.
  501.  
  502. As Vi, Viper's destructive commands can be re-executed by typing ``.''.
  503. However, in addition, Viper keeps track of the history of such
  504. commands. This history can be perused by typing `C-c M-p' and `C-c M-n'.
  505. Having found the appropriate command, it can be then executed by typing
  506. ``.''.  *Note Improvements over Vi::, for more information.
  507.  
  508. 
  509. File: viper,  Node: Insert State,  Next: Replace State,  Prev: Vi State,  Up: States in Viper
  510.  
  511. Insert State
  512. ------------
  513.  
  514.    To avoid confusing the beginner (at Viper level 1 and 2), Viper
  515. makes only the standard Vi keys available in Insert state. The
  516. implication is that Emacs major modes cannot be used Insert state.  It
  517. is strongly recommended that as soon as you are comfortable, make the
  518. Emacs state bindings visible (by changing your user level to 3 or
  519. higher).  *Note Customization::, to see how to do this.
  520.  
  521.    Once this is done, it is possible to do quite a bit of editing in
  522. Insert state. For instance, Emacs has a "yank" command, `C-y', which is
  523. similar to Vi's `p'. However, unlike `p', `C-y' can be used in Insert
  524. state of Viper. Emacs also has a kill ring where it keeps pieces of
  525. text you deleted while editing buffers. The command `M-y' is used to
  526. delete the text previously put back by Emacs' `C-y' or by Vi's `p'
  527. command and reinsert text that was placed on the kill-ring earlier.
  528.  
  529.    This works both in Vi and Insert states.  In Vi state, `M-y' is a
  530. much better alternative to the usual Vi's way of recovering the 10
  531. previously deleted chunks of text. In Insert state, you can use this as
  532. follows. Suppose you deleted a piece of text and now you need to
  533. re-insert it while editing in Insert mode. The key `C-y' will put back
  534. the most recently deleted chunk. If this is not what you want, type
  535. `M-y' repeatedly and, hopefully, you will find the chunk you want.
  536.  
  537.    Finally, in Insert and Replace states, Viper provides the history of
  538. pieces of text inserted in previous insert or replace commands.  These
  539. strings of text can be recovered by repeatedly typing `C-c M-p' or `C-c
  540. M-n' while in Insert or Replace state. (This feature is disabled in the
  541. minibuffer: the above keys are usually bound to other histories, which
  542. are more appropriate in the minibuffer.)
  543.  
  544.    You can call Meta functions from Insert state. The Vi-to-Emacs
  545. toggle key, normally `C-z', is bound to Meta in Insert state. Thus
  546. `M-x' is typed as `C-zx'. The key `_' will now insert itself--it is not
  547. a Meta key in Insert state. (It is well understood that switching Meta
  548. keys around is inconvenient. However, there seems to be no way around
  549. this problem, short of changing Vi ESC key to something else. *Note
  550. Customization::, for the information on `vip-ESC-key', which can be
  551. used to free up `ESC' and designate some other key to do escape from
  552. Insert state to Vi state.)
  553.  
  554.    Other Emacs commands that are useful in Insert state are `C-e' and
  555. `C-a', which move the cursor to the end and the beginning of the
  556. current line, respectively. You can also use `M-f' and `M-b', which
  557. move the cursor forward (or backward) one word.  If your display has a
  558. Meta key, these functions are invoked by holding the Meta key and then
  559. typing `f' and `b', respectively. On displays without the Meta key,
  560. these functions are invoked by typing `C-z f' and `C-z b' (`C-z'
  561. simulates the Meta key in Insert state, as explained above).
  562.  
  563.    When Viper is in Insert state, you will see <I> in the mode line.
  564.  
  565. 
  566. File: viper,  Node: Replace State,  Prev: Insert State,  Up: States in Viper
  567.  
  568. Replace State
  569. -------------
  570.  
  571.    This state is entered through Vi replacement commands, such as `C',
  572. `cw', etc., or by typing `R'. In Replace state, Viper puts <R> in the
  573. mode line to let you know which state is in effect. If Replace state is
  574. entered through `R', Viper stays in that state until the user hits ESC.
  575. If this state is entered via the other replacement commands, then
  576. Replace state is in effect until you hit `ESC' or until you cross the
  577. rightmost boundary of the replacement region. In the latter case, Viper
  578. changes its state from Replace to Insert (which you will notice by the
  579. change in the mode line).
  580.  
  581.    Since Viper runs under Emacs, it is possible to switch between
  582. buffers while in Replace state. You can also move the cursor using the
  583. arrow keys (even on dumb terminals!) and the mouse. Because of this
  584. freedom (which is unattainable in regular Vi), it is possible to take
  585. the cursor outside the replacement region. (This may be necessary for
  586. several reasons, including the need to enable text selection and
  587. region-setting with the mouse.)
  588.  
  589.    The issue then arises as to what to do when the user hits the ESC
  590. key. In Vi, this would cause the text between cursor and the end of the
  591. replacement region to be deleted. But what if, as is possible in Viper,
  592. the cursor is not inside the replacement region?
  593.  
  594.    To solve the problem, Viper keeps track of the last cursor position
  595. while it was still inside the replacement region. So, in the above
  596. situation, Viper would delete text between this position and the end of
  597. the replacement region.
  598.  
  599. 
  600. File: viper,  Node: The Minibuffer,  Next: Multiple Files in Viper,  Prev: States in Viper,  Up: Overview
  601.  
  602. The Minibuffer
  603. ==============
  604.  
  605.    The Minibuffer is where commands are entered in. Editing can be done
  606. by commands from Insert state, namely:
  607.  
  608. `C-h'
  609.      Backspace
  610.  
  611. `C-w'
  612.      Delete Word
  613.  
  614. `C-u'
  615.      Erase line
  616.  
  617. `C-v'
  618.      Quote the following character
  619.  
  620. `RET'
  621.      Execute command
  622.  
  623. `C-g and C-]'
  624.      Emacs quit and abort keys. These may be necessary. *Note Vi
  625.      State::, for an explanation.
  626.  
  627. `M-p and M-n'
  628.      These keys are bound to functions that peruse minibuffer history.
  629.      The precise history to be perused depends on the context. It may
  630.      be the history of search strings, Ex commands, file names, etc.
  631.  
  632.    Most of the Emacs keys are functional in the Minibuffer.  While in
  633. the Minibuffer, Viper tries to make editing resemble Vi's behavior when
  634. the latter is waiting for the user to type an Ex command. In
  635. particular, you can use the regular Vi commands to edit the Minibuffer.
  636. You can switch between the Vi state and Insert state at will, and even
  637. use the replace mode.  Initially, the Minibuffer comes up in Insert
  638. state.
  639.  
  640.    Some users prefer plain Emacs bindings in the Minibuffer. To this
  641. end, set `vip-vi-style-in-minibuffer' to `nil' in `.vip'.  *Note
  642. Customization::, to learn how to do this.
  643.  
  644.    When the Minibuffer changes Viper states, you will notice that the
  645. appearance of the text there changes as well. This is useful because
  646. the Minibuffer has no mode line to tell which Vi state it is in.  The
  647. appearance of the text in the Minibuffer can be changed.  *Note Viper
  648. Specials::, for more details.
  649.  
  650. 
  651. File: viper,  Node: Multiple Files in Viper,  Next: Unimplemented Features,  Prev: The Minibuffer,  Up: Overview
  652.  
  653. Multiple Files in Viper
  654. =======================
  655.  
  656.    Viper can edit multiple files. This means, for example that you
  657. never need to suffer through `No write since last change' errors.  Some
  658. Viper elements are common over all the files.
  659.  
  660. `Textmarkers'
  661.      Textmarkers remember *files and positions*.  If you set marker `a'
  662.      in file `foo', start editing file `bar' and type `'a', then *YOU
  663.      WILL SWITCH TO FILE `foo'*. You can see the contents of a
  664.      textmarker using the Viper command `[<a-z>' where <a-z> are the
  665.      textmarkers, e.g., `[a' to view marker `a' .
  666.  
  667. `Repeated Commands'
  668.      Command repetitions are common over files. Typing `!!' will repeat
  669.      the last `!' command whichever file it was issued from.  Typing
  670.      `.' will repeat the last command from any file, and searches will
  671.      repeat the last search. Ex commands can be repeated by typing
  672.      `:RET'.  Note: in some rare cases, that `:RET' may do something
  673.      dangerous.  However, usually its effect can be undone by typing
  674.      `u'.
  675.  
  676. `Registers'
  677.      Registers are common to files. Also, text yanked with `y' can be
  678.      put back (`p') into any file. The Viper command `]<a-z>', where
  679.      <a-z> are the registers, can be used to look at the contents of a
  680.      register, e.g., type `]a' to view register `a'.
  681.  
  682.      There is one difference in text deletion that you should be aware
  683.      of. This difference comes from Emacs and was adopted in Viper
  684.      because we find it very useful. In Vi, if you delete a line, say,
  685.      and then another line, these two deletions are separated and are
  686.      put back separately if you use the `p' command. In Emacs (and
  687.      Viper), successive series of deletions that are *not interrupted*
  688.      by other commands are lumped together, so the deleted text gets
  689.      accumulated and can be put back as one chunk. If you want to break
  690.      a sequence of deletions so that the newly deleted text could be
  691.      put back separately from the previously deleted text, you should
  692.      perform a non-deleting action, e.g., move the cursor one character
  693.      in any direction.
  694.  
  695. `Absolute Filenames'
  696.      The current directory name for a file is automatically prepended
  697.      to the file name in any `:e', `:r', `:w', etc., command (in Emacs,
  698.      each buffer has a current directory).  This directory is inserted
  699.      in the Minibuffer once you type space after `:e, r', etc. Viper
  700.      also supports completion of file names and Ex commands (`TAB'),
  701.      and it keeps track of command and file history (`M-p', `M-n').
  702.      Absolute filenames are required less often in Viper.
  703.  
  704.      You should be aware that Emacs interprets `/foo/bar//bla' as
  705.      `/bla' and `/foo/~/bar' as `~/bar'. This is designed to minimize
  706.      the need for erasing path names that Emacs suggests in its
  707.      prompts, if a suggested path name is not what you wanted.
  708.  
  709.      The command `:cd' will change the default directory for the
  710.      current Emacs buffer. The Ex command `:e' will interpret the
  711.      filename argument in `csh', by default. *Note Customization::, if
  712.      you want to change this.
  713.  
  714. Currently undisplayed files can be listed using the `:ar' command.  The
  715. command `:n' can be given counts from the `:ar' list to switch to other
  716. files.
  717.  
  718. 
  719. File: viper,  Node: Unimplemented Features,  Prev: Multiple Files in Viper,  Up: Overview
  720.  
  721. Unimplemented Features
  722. ======================
  723.  
  724.    Unimplemented features include:
  725.  
  726.    * `:ab' and `:una' are not implemented.  Both `:map' and `:ab' are
  727.      considered obsolete, since Emacs has much more powerful facilities
  728.      for defining keyboard macros and abbreviations.
  729.  
  730.    * `:set option?' is not implemented. The current `:set' can also be
  731.      used to set Emacs variables.
  732.  
  733.    * `:se list' requires modification of the display code for Emacs, so
  734.      it is not implemented.  A useful alternative is `cat -t -e file'.
  735.      Unfortunately, it cannot be used directly inside Emacs, since
  736.      Emacs will obdurately change `^I' back to normal tabs.
  737.  
  738. 
  739. File: viper,  Node: Improvements over Vi,  Next: Customization,  Prev: Overview,  Up: Top
  740.  
  741. Improvements over Vi
  742. ********************
  743.  
  744.    Some common problems with Vi and Ex have been solved in Viper. This
  745. includes better implementation of existing commands, new commands, and
  746. the facilities provided by Emacs.
  747.  
  748. * Menu:
  749.  
  750. * Basics::            Basic Viper differences, Multi-file effects.
  751. * Undo and Backups::        Multiple undo, auto-save, backups and changes
  752. * History::            History for Ex and Vi commands.
  753. * Macros and Registers::    Keyboard Macros (extended ".") @reg execution.
  754. * Completion::            Filename and Command Completion for Ex.
  755. * Improved Search::        Incremental Search and Buffer Content Search.
  756. * Abbreviation Facilities:: Normal Abbrevs, Templates, and Dynamic Abbrevs.
  757. * Movement and Markers::    Screen Editor movements, viewing textmarkers.
  758. * New Commands::        Commands that do not exist in Vi.
  759. * Useful Packages::         A Sampling of some Emacs packages, and things
  760.                 you should know about.
  761.  
  762. 
  763. File: viper,  Node: Basics,  Next: Undo and Backups,  Prev: Improvements over Vi,  Up: Improvements over Vi
  764.  
  765. Basics
  766. ======
  767.  
  768.    The Vi command set is based on the idea of combining motion commands
  769. with other commands. The motion command is used as a text region
  770. specifier for other commands.  We classify motion commands into "point
  771. commands" and "line commands".
  772.  
  773.    The point commands are:
  774.  
  775.      `h', `l', `0',  `$', `w', `W', `b', `B', `e', `E', `(', `)', `/',
  776.      `?', ``', `f', `F', `t', `T', `%', `;', `,', `^'
  777.  
  778.    The line commands are:
  779.  
  780.      `j', `k', `+', `-', `H', `M', `L', `{', `}', `G', `'',  `[[',
  781.      `]]', `[]'
  782.  
  783. If a point command is given as an argument to a modifying command, the
  784. region determined by the point command will be affected by the modifying
  785. command. On the other hand, if a line command is given as an argument
  786. to a modifying command, the region determined by the line command will
  787. be enlarged so that it will become the smallest region properly
  788. containing the region and consisting of whole lines (we call this
  789. process "expanding the region"), and then the enlarged region will be
  790. affected by the modifying command.  Text Deletion Commands (*Note
  791. Deleting Text::), Change commands (*Note Changing Text::), even Shell
  792. Commands (*Note Shell Commands::) use these commands to describe a
  793. region of text to operate on.  Thus, type `dw' to delete a word, `>}'
  794. to shift a paragraph, or `!'afmt' to format a region from `point' to
  795. textmarker `a'.
  796.  
  797.    Viper adds the region specifiers `r' and `R'. Emacs has a special
  798. marker called "mark". The text-area between the current cursor position
  799. "point" and the "mark" is called the "region".  `r' specifies the raw
  800. region and `R' is the expanded region (i.e., the minimal contiguous
  801. chunk of full lines that contains the raw region).  `dr' will now
  802. delete the region, `>r' will shift it, etc.  `r,R' are not motion
  803. commands, however. The special mark is set by `m.' and other commands.
  804. *Note Marking::, for more info.
  805.  
  806.    Viper also adds counts to most commands for which it would make
  807. sense.
  808.  
  809.    In the Overview chapter, some Multiple File issues were discussed
  810. (*Note Multiple Files in Viper::). In addition to the files, Emacs has
  811. buffers. These can be seen in the `:args' list and switched using
  812. `:next' if you type `:set ex-cycle-through-non-files t', or specify
  813. `(setq ex-cycle-through-non-files t)' in your `.vip' file. *Note
  814. Customization::, for details.
  815.  
  816. 
  817. File: viper,  Node: Undo and Backups,  Next: History,  Prev: Basics,  Up: Improvements over Vi
  818.  
  819. Undo and Backups
  820. ================
  821.  
  822.    Viper provides multiple undo. The number of undo's and the size is
  823. limited by the machine. The Viper command `u' does an undo. Undo can be
  824. repeated by typing `.' (a period). Another `u' will undo the undo, and
  825. further `.' will repeat it. Typing `u' does the first undo, and changes
  826. the direction.
  827.  
  828.    Since the undo size is limited, Viper can create backup files and
  829. auto-save files. It will normally do this automatically. It is possible
  830. to have numbered backups, etc. For details, *note Backup and Auto-Save:
  831. (emacs)Backup.
  832.  
  833.    The results of the 9 previous changes are available in the 9 numeric
  834. registers, as in Vi. The extra goody is the ability to *view* these
  835. registers, in addition to being able to access them through `p' and
  836. `M-y' (*Note Insert State::, for details.) The Viper command `]
  837. register' will display the contents of any register, numeric or
  838. alphabetical. The related command `[ textmarker' will show the text
  839. around the textmarker. `register' and `textmarker' can be any letters
  840. from a through z.
  841.  
  842. 
  843. File: viper,  Node: History,  Next: Macros and Registers,  Prev: Undo and Backups,  Up: Improvements over Vi
  844.  
  845. History
  846. =======
  847.  
  848.    History is provided for Ex commands, Vi searches, file names, pieces
  849. of text inserted in earlier commands that use Insert or Replace state,
  850. and for destructive commands in Vi state. These are useful for fixing
  851. those small typos that screw up searches and `:s', and for eliminating
  852. routine associated with repeated typing of file names or pieces of text
  853. that need to be inserted frequently.  At the `:' or `/' prompts in the
  854. Minibuffer, you can do the following:
  855.  
  856. `M-p and M-n'
  857.      To move to previous and next history items. This causes the history
  858.      items to appear on the command line, where you can edit them, or
  859.      simply type Return to execute.
  860.  
  861. `M-r and M-s'
  862.      To search backward and forward through the history.
  863.  
  864. `RET'
  865.      Type RET to accept a default (which is displayed in the prompt).
  866.  
  867.    The history of insertions  can be perused by typing `C-c M-p' and
  868. `C-c M-n' while in Insert or Replace state.  The history of destructive
  869. Vi commands can be perused via the same keys when Viper is in Vi state.
  870. *Note Viper Specials::, for details.
  871.  
  872.    All Ex commands have a file history. For instance, typing `:e', space
  873. and then `M-p' will bring up the name of the previously typed file
  874. name. Repeatedly typing `M-p', `M-n', etc., will let you browse through
  875. the file history.
  876.  
  877.    Similarly, commands that have to do with switching buffers have a
  878. buffer history, and commands that expect strings or regular expressions
  879. keep a history on those items.
  880.  
  881. 
  882. File: viper,  Node: Macros and Registers,  Next: Completion,  Prev: History,  Up: Improvements over Vi
  883.  
  884. Macros and Registers
  885. ====================
  886.  
  887.    Viper facilitates the use of Emacs-style keyboard macros. `@#' will
  888. start a macro definition.  As you type, the commands will be executed,
  889. and remembered (This is called "learn mode" in some editors.)
  890. `@register' will complete the macro, putting it into `register', where
  891. `register' is any character from `a' through `z'. Then you can execute
  892. this macro using `@register'. It is, of course, possible to yank some
  893. text into a register and execute it using `@register'. Typing `@@',
  894. `@RET', or `@LF' will execute the last macro that was executed using
  895. `@register'.
  896.  
  897.    Viper will automatically lowercase the register, so that pressing the
  898. `SHIFT' key for `@' will not create problems. This is for `@' macros
  899. and `"p' *only*. In the case of `y', `"Ayy' will append to *register
  900. a*. For `[,],',`', it is an error to use a Uppercase register name.
  901.  
  902.    The contents of a register can be seen by `]register'. (`[textmarker'
  903. will show the contents of a textmarker).
  904.  
  905.    The last keyboard macro can also be executed using `*', and it can
  906. be yanked into a register using `@!register'.  This is useful for Emacs
  907. style keyboard macros defined using `C-x(' and `C-x)'. Emacs keyboard
  908. macros have more capabilities.  *Note Keyboard Macros: (emacs)Keyboard
  909. Macros, for details.
  910.  
  911.    Keyboard Macros allow an interesting form of Query-Replace:
  912. `/pattern' or `n' to go to the next pattern (the query), followed by a
  913. Keyboard Macro execution `@@' (the replace).
  914.  
  915.    Viper also provides Vi-style macros. *Note Vi Macros::, for details.
  916.  
  917. 
  918. File: viper,  Node: Completion,  Next: Improved Search,  Prev: Macros and Registers,  Up: Improvements over Vi
  919.  
  920. Completion
  921. ==========
  922.  
  923.    Completion is done when you type `TAB'. The Emacs completer does not
  924. grok wildcards in filenames. Once you type a wildcard, the completer
  925. will no longer work for that path.  Remember that Emacs interprets a
  926. file name of the form `/foo//bar' as `/bar' and `/foo/~/bar' as `~/bar'.
  927.  
  928. 
  929. File: viper,  Node: Improved Search,  Next: Abbreviation Facilities,  Prev: Completion,  Up: Improvements over Vi
  930.  
  931. Improved Search
  932. ===============
  933.  
  934.    Viper provides buffer search, the ability to search the buffer for a
  935. region under the cursor. You have to turn this on by calling
  936.  
  937.      (vip-buffer-search-enable)
  938.  
  939. Then, the key `g' will take movement commands like `w,/', etc., to find
  940. a region and search for the contents of this region. This command is
  941. very useful to search for variable names, etc., in a program. The
  942. search can be repeated by `n', or reversed by `N'.
  943.  
  944.    Emacs provides incremental search. As you type the string in, the
  945. cursor will move to the next match. You can snarf words from the buffer
  946. as you go along. Incremental Search is normally bound to `C-s' and
  947. `C-r'. *Note Customization::, to find out how to change the bindings of
  948. `C-r or C-s'.  For details, *note Incremental Search:
  949. (emacs)Incremental Search.
  950.  
  951.    Viper also provides a query replace function that prompts through the
  952. Minibuffer. It is invoked by the `Q' key in Vi state.
  953.  
  954.    On a window display, Viper supports mouse search, i.e., you can
  955. search for a word by clicking on it. *Note Viper Specials::, for
  956. details.
  957.  
  958.    Finally, on a window display, Viper highlights search patterns as it
  959. finds them. This is done through what is known as *faces* in Emacs. The
  960. variable that controls how search patterns are highlighted is
  961. `vip-search-face'.  If you don't want any highlighting at all, put
  962.      (copy-face 'default 'vip-search-face)
  963.  
  964. in `~/.vip'. If you want to change how patterns are highlighted, you
  965. will have to set the variable `vip-search-face' to some other face,
  966. such as `highlight'. If none of the existing faces fits the bill, you
  967. may have to create your own. Further details on faces can be found in
  968. the Emacs Lisp Manual.
  969.  
  970. 
  971. File: viper,  Node: Abbreviation Facilities,  Next: Movement and Markers,  Prev: Improved Search,  Up: Improvements over Vi
  972.  
  973. Abbreviation Facilities
  974. =======================
  975.  
  976.    It is possible in Emacs to define abbrevs based on the contents of
  977. the buffer.  Sophisticated templates can be defined using the Emacs
  978. abbreviation facilities. *Note Abbreviations: (emacs)Abbrevs, for
  979. details.
  980.  
  981.    Emacs also provides Dynamic Abbreviations. Given a partial word,
  982. Emacs will search the buffer to find an extension for this word. For
  983. instance, one can type `Abbreviations' by typing `A', followed by a
  984. keystroke that completed the `A' to `Abbreviations'. Repeated typing
  985. will search further back in the buffer, so that one could get `Abbrevs'
  986. by repeating the keystroke, which appears earlier in the text. Emacs
  987. binds this to `ESC /', so you will have to find a key and bind the
  988. function `dabbrev-expand' to that key.  Facilities like this make Vi's
  989. `:ab' command obsolete.
  990.  
  991. 
  992. File: viper,  Node: Movement and Markers,  Next: New Commands,  Prev: Abbreviation Facilities,  Up: Improvements over Vi
  993.  
  994. Movement and Markers
  995. ====================
  996.  
  997.    Viper can be set free from the line-limited movements in Vi, such as
  998. `l' refusing to move beyond the line, `ESC' moving one character back,
  999. etc. These derive from Ex, which is a line editor. If your `.vip'
  1000. contains
  1001.  
  1002.      `(setq vip-ex-style-motion nil)'
  1003.  
  1004. the motion will be a true screen editor motion. One thing you must then
  1005. watch out for is that it is possible to be on the end-of-line character.
  1006. The keys `x' and `%' will still work correctly, i.e., as if they were
  1007. on the last character.
  1008.  
  1009.    Textmarkers in Viper remember the file and the position, so that you
  1010. can switch files by simply doing `'a'. If you set up a regimen for using
  1011. Textmarkers, this is very useful. Contents of textmarkers can be viewed
  1012. by `[marker'. (Contents of registers can be viewed by `]register').
  1013.  
  1014.